package no.sachmuld.methodcombination.examples.annotation.aopstyle.foo;

import no.sachmuld.methodcombination.api.CrosscuttingBehaviour;
import no.sachmuld.methodcombination.api.MethodInvocation;

import java.util.Arrays;

/**
 *
 */
public class LoggingBehaviour extends CrosscuttingBehaviour {

    @Override
    public void before(MethodInvocation<Void> methodInvocation) {
        System.out.println("before " + toString(methodInvocation));
    }

    @Override
    public void after(MethodInvocation<Void> methodInvocation) {
        System.out.println("after " + toString(methodInvocation));
    }

    private String toString(MethodInvocation methodInvocation) {
        StringBuilder sb = new StringBuilder();
        sb.append(methodInvocation.getThis());
        sb.append(" : ");
        sb.append(methodInvocation.getMethod());
        sb.append(" : ");
        sb.append(Arrays.asList(methodInvocation.getArguments()));
        return sb.toString();
    }
}
